#include "lib/Utils/Square.h"

#include "lib/Utils/debug_includes.h"

Square::Square(int a_Id)
: m_Id(a_Id)
, m_Visited(0)
, m_Connections(4, 0)
{

}

void Square::SetUp(Square* a_Sq)
{

	m_Connections[SQC_UP] = a_Sq;
}

void Square::SetRight(Square* a_Sq)
{

	m_Connections[SQC_RIGHT] = a_Sq;
}

void Square::SetDown(Square* a_Sq)
{

	m_Connections[SQC_DOWN] = a_Sq;
}

void Square::SetLeft(Square* a_Sq)
{

	m_Connections[SQC_LEFT] = a_Sq;
}

int Square::GetId() const
{

	return m_Id;
}

bool Square::IsEdgePiece() const
{

	return !m_Connections[SQC_UP] || !m_Connections[SQC_RIGHT] || !m_Connections[SQC_DOWN] || !m_Connections[SQC_LEFT];
}

bool Square::IsVisited() const
{

	return m_Visited != 0;
}

void Square::SetVisited(Square* a_Who)
{

	m_Visited = a_Who;
}

void Square::RemoveLink(Square *a_ToRemove)
{
	_ASSERT(a_ToRemove);

	for(std::vector<Square*>::iterator l_IT=m_Connections.begin() ; l_IT<m_Connections.end() ; l_IT++) {
		if(*l_IT == a_ToRemove) {
			*l_IT = 0;
		}
	}
}

const std::vector<Square*>& Square::GetConnections() const
{

	return m_Connections;
}

Square::~Square(void)
{
}
